#! /usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Teny

from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import render,redirect

class AuthMiddleware(MiddlewareMixin):
    def process_request(self, request):
        # print('come')
        # return None
        if request.path_info in ['/d1/login/', '/d1/image/code/']:
            return

        session_dict = request.session.get('info')
        # request.session['info'] 这里不用，如果未获取到会报错
        # print(session_dict)
        if session_dict:
            return

        return redirect('/d1/login/')

    # def process_response(self, request, response):
    #     print('go')
    #     return response

